// bounds upon which coordinates are computed
Integrator x1Bound;
Integrator x2Bound;
Integrator y1Bound;
Integrator y2Bound;

float originalX1; 
float originalY1; 
float originalX2; 
float originalY2;

float zoomPerc = .2;

float xToYRatio;      

boolean zoomInitialized = false;

void initZoom()
{
  if( zoomInitialized )
    return;
  x1Bound = new Integrator( 0.0 );
  x2Bound = new Integrator( windowWidth );
  y1Bound = new Integrator( 0.0 );
  y2Bound = new Integrator( windowHeight );
  
  originalX1 = 0.0;
  originalX2 = (float) windowWidth;
  originalY1 = 0.0;
  originalY2 = (float) windowHeight;
  
  xToYRatio = (float)windowWidth / (float)windowHeight;
  
  zoomInitialized = true;

}

boolean isZooming()
{
  return x1Bound.isTargeting() && x2Bound.isTargeting() && y1Bound.isTargeting() && y2Bound.isTargeting();
}

void zoomUpdate()
{
  if( x1Bound.isTargeting() )
    x1Bound.update();
  if( x2Bound.isTargeting() )
    x2Bound.update();
  if( y1Bound.isTargeting() )
    y1Bound.update();
  if( y2Bound.isTargeting() )
    y2Bound.update();

}

void zoomIn()
{
  println("zoom in");
  float changeInX = zoomPerc * (x2Bound.value - x1Bound.value);
  float changeInY = zoomPerc * (y2Bound.value - y1Bound.value);//changeInX / xToYRatio ;
  
  //println( "x2Bound.value - x1Bound.value = " + (x2Bound.value - x1Bound.value) );  
  //println( "change in y = " + changeInY );
  //x1Bound.target( x1Bound.value + changeInX );
  //x2Bound.target( x2Bound.value - changeInX );
  y1Bound.target( y1Bound.value + changeInY );
  y2Bound.target( y2Bound.value - changeInY );
}

void zoomOut()
{
  println("zoom out" );
  float changeInX = zoomPerc * (x2Bound.value - x1Bound.value);
  float changeInY = zoomPerc * (y2Bound.value - y1Bound.value);//float changeInY = changeInX / xToYRatio ;

  //x1Bound.target( x1Bound.value - changeInX );
  //x2Bound.target( x2Bound.value + changeInX );
  y1Bound.target( y1Bound.value - changeInY );
  y2Bound.target( y2Bound.value + changeInY );
}

float tx(float x)
{
  return map( x, x1Bound.value, x2Bound.value, originalX1, originalX2 );//originalX1, originalX2, x1Bound.value, x2Bound.value );
}

float ty(float y)
{
  return map( y, y1Bound.value, y2Bound.value, originalY1, originalY2 );//originalY1, originalY2, y1Bound.value, y2Bound.value );
}

float untx(float x)
{
  return map( x, originalX1, originalX2, x1Bound.value, x2Bound.value );//originalX1, originalX2, x1Bound.value, x2Bound.value );
}

float unty(float y)
{
  return map( y, originalY1, originalY2, y1Bound.value, y2Bound.value );
}
